
  <div class="ibox float-e-margins">
    <div class="ibox-title" style="border: none;">
      <h5 style="color: #00afef"><i>Add</i></h5>
        <div class="ibox-tools add">
          <button id="save_location" class="btn btn-primary btn-sm save-btn-tab" type="">Save</button>
          <button id="cancel_add" class="btn-outline btn btn-primary btn-sm add-cancel cancel-btn-tab" >Cancel</button>
        </div>
    </div>
    <div class="ibox-content">
      <form class="form-horizontal" id="assetLocation">
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Location Code</label>
            <div class="col-lg-4">
                <input name="locCode" type="text" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Location Description</label>
            <div class="col-lg-4">
                <input name="locDesc" type="text" class="form-control">
            </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">Enable</label>
          <div class="col-lg-1">
            <input type="checkbox" value="ok" name="locEna" class="i-checks" checked>
          </div>
        </div>
      </div>
      </form>
    </div>
  </div>

  <script type="text/javascript">
  $(document).ready(function() {
    $('#assetLocation').data('serialize',$('#assetLocation').serialize());
    $('select').chosen({width: '100%'});
    $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });

        $(document).on('click','#save_location',function(){
            if($("#assetLocation" ).valid() == true){
                $.ajax({
                  url:"<?php echo base_url($this->session->userdata('forajax') . '/insert'); ?>",
                  method:'post',
                  data:$('#assetLocation').serialize(),
                  dataType:'json',
                  success: function (data) {
                      if(data.err == 1){
                        notifymsg('danger','Already Exist');
                      }else{
                        $('#add-link').remove();
                        $('#add').remove();
                        $('#tab-list-2 a:first').tab('show');
                        $('#count_add').val('0');
                        notifymsg('success','<b>Success</b>: Data Saved.');
                      }

                  },
                  beforeSend: function(){

                  }
              });
            }
        });

        function alert_cancel(){
                if($('#assetLocation').serialize()!=$('#assetLocation').data('serialize')){
                // Form has changed!!!
                swal({
                  title: "Are you sure?",
                  text: "Your work will not be save",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "Leave",
                  cancelButtonText: "Stay",
                  closeOnConfirm: true,
                  closeOnCancel: true },
              function (isConfirm) {
                  if (isConfirm) {
                    swal("success");
                      close_add(); active_search();
                      notifyClass("clear","");
                  } else {
                      swal("Cancelled");
                  }
              });
                }else{
                    close_add(); active_search();
                    notifymsg("hide","hide");
                }
            }
        $('#cancel_add').click(function(){
            alert_cancel();
        });

        $('#addX').click(function(){
            alert_cancel();
        });

        $("#assetLocation").validate({
                 rules: {
                     locCode: {
                        required: true
                     },
                     locDesc: {
                      required : true
                     }
                 }
        });
  });
  </script>